package com.mangocheese.subject.infra.basic.service.impl;

import com.alibaba.fastjson.JSON;
import com.mangocheese.subject.infra.basic.entity.SubjectLabel;
import com.mangocheese.subject.infra.basic.mapper.SubjectLabelDao;
import com.mangocheese.subject.infra.basic.service.SubjectLabelService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 题目标签表(SubjectLabel)表服务实现类
 *
 * @author makejava
 * @since 2023-11-18 21:43:54
 */
@Service("subjectLabelService")
@Slf4j
public class SubjectLabelServiceImpl implements SubjectLabelService {
    @Resource
    private SubjectLabelDao subjectLabelDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectLabel queryById(Long id) {
        return this.subjectLabelDao.queryById(id);
    }

    /**
     * 通过ID查询多条数据
     *
     * @param list 主键集合
     * @return 实例对象
     */
    @Override
    public List<SubjectLabel> queryByIds(List<Long> list) {
        return this.subjectLabelDao.queryByIds(list);
    }

    @Override
    public List<SubjectLabel> queryLabel(SubjectLabel subjectLabel) {
        if(log.isInfoEnabled()){
            log.info("SubjectLabelServiceImpl.queryLabel.pojo:{}", JSON.toJSONString(subjectLabel));
        }
        List<SubjectLabel> subjectLabels = this.subjectLabelDao.queryLabel(subjectLabel);
        if(log.isInfoEnabled()){
            log.info("SubjectLabelServiceImpl.queryLabel.pojoList:{}", JSON.toJSONString(subjectLabels));
        }
        return subjectLabels;
    }

    /**
     * 新增数据
     *
     * @param subjectLabel 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(SubjectLabel subjectLabel) {
        return this.subjectLabelDao.insert(subjectLabel) > 0;
    }

    /**
     * 修改数据
     *
     * @param subjectLabel 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(SubjectLabel subjectLabel) {
        if(log.isInfoEnabled()){
            log.info("SubjectLabelServiceImpl.update.pojo:{}", JSON.toJSONString(subjectLabel));
        }
        return this.subjectLabelDao.update(subjectLabel) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.subjectLabelDao.deleteById(id) > 0;
    }
}
